﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity.Admin;

namespace Service
{
    public class InquiryParameterService : BaseService<InquiryParameter>
    {
        public InquiryParameterService(DBEntities db)
            : base(db)
        { }

        public override InquiryParameter Create(InquiryParameter entity)
        {
            Nullable<int> maxOrder = db.InquiryParameters.Max(p => p.OrderIndex);
            entity.OrderIndex = maxOrder.HasValue ? maxOrder.Value + 1 : 1;
            if (string.IsNullOrWhiteSpace(entity.ID))
            {
                entity.ID = Guid.NewGuid().ToString();
            }
            return base.Create(entity);
        }

        public override InquiryParameter Save(InquiryParameter entity)
        {
            return base.Save(entity);
        }

        public InquiryParameter CreateOrSave(InquiryParameter entity)
        {
            if (string.IsNullOrWhiteSpace(entity.ID))
            {
                return Create(entity);
            }
            else
            {
                return Save(entity);
            }
        }

    }
}
